using System.Collections.ObjectModel;
using HMCollada.FX;
using HMCollada.Core;
using System.Xml;
using System;

namespace HMCollada.Core {
    internal struct HMColladaAccessor {
        internal int count;
        internal int offset;
        internal string source;
        internal int stride;
        internal Collection<HMColladaParam> param;
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        private static HMColladaAccessor LoadAccessor() {
            HMColladaAccessor newAccessor = new HMColladaAccessor();
            newAccessor.count = int.Parse(colladaReader.GetAttribute("count"));
            try { newAccessor.offset = int.Parse(colladaReader.GetAttribute("offset")); } catch { Console.WriteLine("Skipping optional offset parameter"); }
            newAccessor.source = colladaReader.GetAttribute("source");
            try { newAccessor.stride = int.Parse(colladaReader.GetAttribute("stride")); } catch { Console.WriteLine("Skipping optional stride parameter"); }

            newAccessor.param = new Collection<HMColladaParam>();

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "param": newAccessor.param.Add(LoadParam()); break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "accessor");

            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newAccessor;
        }
    }
}